using System;
using FU.Capstones.IMS.Web.Common;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;

namespace FU.Capstones.IMS.Web.Silverlight.Models
{
    public class EmployeeListModel : ModelBase
    {
        public EmployeeListModel()
        {
            client.DeleteEmployeeCompleted += DoDeleteEmployeeCompleted;
            client.GetEmployeeCollectionCompleted += DoGetEmployeeCollectionCompleted;
            client.GetSingleEmployeeCompleted += DoGetSingleEmployeeCompleted;
            client.SearchEmployeeCompleted += DoSearchEmployeeCompleted;
            client.GetRoleCollectionCompleted += DoGetRoleCollectionCompleted;
            client.GetEmploymentTypeCollectionCompleted += DoGetEmploymentTypeCollectionCompleted;
            client.UndoDeleteEmployeeCompleted += DoUndoDeleteEmployeeCompleted;
        }

        #region UndoDeleteEmployee

        public event EventHandler<FeedbackCompletedEventArgs> UndoDeleteEmployeeCompleted;

        public int UndoDeleteEmployeeAsync(int objID)
        {
            client.UndoDeleteEmployeeAsync(objID);
            return WebConstants.MagicNumer;
        }

        void DoUndoDeleteEmployeeCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (UndoDeleteEmployeeCompleted != null)
            {
                UndoDeleteEmployeeCompleted(sender, e);
            }
        }

        #endregion

        #region GetEmploymentTypeCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<EmploymentType>> GetEmploymentTypeCollectionCompleted;
        
        public int GetEmploymentTypeCollectionAsync()
        {
            client.GetEmploymentTypeCollectionAsync(false);
            return WebConstants.MagicNumer;
        }
        
        void DoGetEmploymentTypeCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<EmploymentType> e)
        {
            if(GetEmploymentTypeCollectionCompleted!=null)
            {
                GetEmploymentTypeCollectionCompleted(sender, e);
            }
        }

        #endregion

        #region GetRoleCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Role>> GetRoleCollectionCommpleted;

        public int GetRoleCollectionAsync()
        {
            client.GetRoleCollectionAsync(false);
            return WebConstants.MagicNumer;
        }

        void DoGetRoleCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Role> e)
        {
            if (GetRoleCollectionCommpleted != null)
            {
                GetRoleCollectionCommpleted(sender, e);
            }
        }

        #endregion
        
        #region SearchEmployee

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Employee>> SearhEmployeeCompleted;

        public int SearchEmployeeAsync(EmployeeCriteria criteria)
        {
            client.SearchEmployeeAsync(criteria);
            return WebConstants.MagicNumer;
        }

        void DoSearchEmployeeCompleted(object sender, CollectionFeedbackCompletedEventArgs<Employee> e)
        {
            if (SearhEmployeeCompleted != null)
            {
                SearhEmployeeCompleted(sender, e);
            }
        }

        #endregion

        #region GetEmployeeCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Employee>> GetEmployeeCollectionCompleted;

        public int GetEmployeeCollectionAsync(bool isShowAll)
        {
            client.GetEmployeeCollectionAsync(isShowAll);
            return WebConstants.MagicNumer;
        }

        void DoGetEmployeeCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Employee> e)
        {
            if (GetEmployeeCollectionCompleted != null)
            {
                GetEmployeeCollectionCompleted(sender, e);
            }
        }

        #endregion

        #region DeleteEmployee

        public event EventHandler<FeedbackCompletedEventArgs> DeleteEmployeeCompleted;

        public int DeleteEmployeeAsync(int data)
        {
            client.DeleteEmployeeAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoDeleteEmployeeCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (DeleteEmployeeCompleted != null)
            {
                DeleteEmployeeCompleted(sender, e);
            }
        }

        #endregion

        #region GetSingleEmployee

        public event EventHandler<SingleFeedbackCompletedEventArgs<Employee>> GetSingleEmployeeCompleted;

        public int GetSingleEmployeeAsync(int employeeID)
        {
            client.GetSingleEmployeeAsync(employeeID);
            return WebConstants.MagicNumer;
        }

        void DoGetSingleEmployeeCompleted(object sender, SingleFeedbackCompletedEventArgs<Employee> e)
        {
            if (GetSingleEmployeeCompleted != null)
            {
                GetSingleEmployeeCompleted(sender, e);
            }
        }

        #endregion
    }
}